//go:build darwin

package notify

import (
	"github.com/progrium/macdriver/macos/foundation"
	"github.com/progrium/macdriver/objc"
)

type MacNotify struct{}

func (o MacNotify) Push(title, informativeText string, params ...string) error {
	bundle := foundation.Bundle_MainBundle().Class()
	objc.ReplaceMethod(bundle, objc.Sel("bundleIdentifier"), func(_ objc.IObject) string {
		return "com.lyuanbo.stock"
	})

	objc.WithAutoreleasePool(func() {
		notification := objc.Call[objc.Object](objc.GetClass("NSUserNotification"), objc.Sel("new"))
		notification.Autorelease()
		objc.Call[objc.Void](notification, objc.Sel("setTitle:"), title)
		objc.Call[objc.Void](notification, objc.Sel("setInformativeText:"), informativeText)

		center := objc.Call[objc.Object](objc.GetClass("NSUserNotificationCenter"), objc.Sel("defaultUserNotificationCenter"))
		objc.Call[objc.Void](center, objc.Sel("deliverNotification:"), notification)
	})

	return nil
}
